package org.columba.mail.gui.config.accountwizard;

import org.columba.ristretto.message.Address;

import com.deruan.hotcore.base.common.bean.MailAccountBean;
import com.deruan.hotcore.base.common.service.MailAccountService;
import com.deruan.hotcore.common.service.ServiceFactory;
import com.deruan.hotcore.platform.PlatFormContex;

import net.javaprog.ui.wizard.DataModel;
import net.javaprog.ui.wizard.WizardModelEvent;
import net.javaprog.ui.wizard.WizardModelListener;

public class AccountCreatorForRemote implements WizardModelListener
{
	protected DataModel data;

	public AccountCreatorForRemote(DataModel data) 
	{
		this.data = data;
	}

	public void wizardFinished(WizardModelEvent e) 
	{
		if(PlatFormContex.loginStatus==PlatFormContex.ONLINE)
		{
			MailAccountBean bean = new MailAccountBean();
			bean.setAccountName((String) data.getData("Identity.accountName"));
	        bean.setEmailAddress(((Address) data.getData("Identity.address")).getMailAddress());
			bean.setIsPopDefault(false);
			bean.setIsSmtDefault(false);
			bean.setOrganisasion("");
			bean.setPopHost((String) data.getData("IncomingServer.host"));
			bean.setPopPort(110);
			bean.setPopUser((String) data.getData("IncomingServer.login"));
			bean.setSmtHost((String) data.getData("OutgoingServer.host"));
			bean.setSmtPort(25);
			bean.setSmtUser((String) data.getData("IncomingServer.login"));
			bean.setUserId(PlatFormContex.userId);
			MailAccountService service = 
				(MailAccountService)ServiceFactory.getService(MailAccountService.class);
			try
			{
				service.create(bean);
			}
			catch (Exception ae) 
			{
				ae.printStackTrace();
			}
		}
	}

	public void stepShown(WizardModelEvent e) {
	}

	public void wizardCanceled(WizardModelEvent e) {
	}

	public void wizardModelChanged(WizardModelEvent e) {
	}
}
